package com.hengtongxing.hejiayun.homepage;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.google.gson.Gson;
import com.hengtongxing.hejiayun.R;
import com.hengtongxing.hejiayun.base.BaseActivity;
import com.hengtongxing.hejiayun.base.DataCallBack;
import com.hengtongxing.hejiayun.bean.RefundAmountBean;
import com.hengtongxing.hejiayun.bean.RefundRecordBean;
import com.hengtongxing.hejiayun.homepage.adapter.GoodsListAdapter;
import com.hengtongxing.hejiayun.homepage.adapter.RefundRecordAdapter;
import com.hengtongxing.hejiayun.mine.model.MineModelImpl;
import com.hengtongxing.hejiayun.shop.ShopGoodsDetailsActivity;
import com.hengtongxing.hejiayun.widget.AppTitleBar;
import com.hengtongxing.hejiayun.widget.WrapContentLinearLayoutManager;

import java.util.ArrayList;
import java.util.List;

public class RefundRecordActivity extends BaseActivity {
    @BindView(R.id.title_bar)
    AppTitleBar titleBar;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private Integer id;
    private MineModelImpl mineModel;
    private List<RefundRecordBean.Data> data = new ArrayList<>();
    private RefundRecordAdapter listAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_refund_record);
        ButterKnife.bind(this);
        mineModel = new MineModelImpl();
        initView();
        initData();
        initEvent();


    }

    private void initEvent() {
        listAdapter = new RefundRecordAdapter(data);
        recyclerView.setLayoutManager(new WrapContentLinearLayoutManager(mActivity));
        recyclerView.setAdapter(listAdapter);

        listAdapter.setOnCallBackListener(position -> {
            Intent intent = new Intent(this, RefundDetailsActivity.class);
            intent.putExtra("position",position);
            intent.putExtra("id",data.get(position).getId());
            intent.putExtra("order_goods_id",data.get(position).getOrder_goods_id());
            intent.putExtra("shop_order_id",data.get(position).getShop_order_id());
            intent.putExtra("goods_status",data.get(position).getGoods_status());
            intent.putExtra("status",data.get(position).getStatus());
            intent.putExtra("remark",data.get(position).getRemark());
            intent.putExtra("refund_amount",data.get(position).getRefund_amount());
            intent.putExtra("depict",data.get(position).getDepict());
            intent.putExtra("create_date",data.get(position).getCreate_date());
            intent.putExtra("delivery_no",data.get(position).getDelivery_no());
            intent.putExtra("pic",new Gson().toJson(data.get(position).getPic()));
            startActivity(intent);
        });
    }

    private void initView() {
        Intent intent = getIntent();
        id = intent.getIntExtra("id",0);

    }


    private void initData() {


    }

    @Override
    protected void onResume() {
        super.onResume();
        mineModel.rundsGoodsLog(id, new DataCallBack<RefundRecordBean>() {
            @Override
            public void onSuccessful(RefundRecordBean bean) {
                data.clear();
                data.addAll(bean.getData());
                listAdapter.notifyDataSetChanged();
            }

            @Override
            public void onFailed(String msg, String code) {

            }
        });
    }
}